package dolf.objects;

public class Vector extends Point implements java.io.Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Vector(double xv, double yv){
		super(xv,yv);
	}
	public Vector(int xv, int yv){
		super(xv,yv);
	}
	public Vector getCopy(){
		return (new Vector(this.getX(), this.getY()));
	}
	public Vector add(Vector vec){
		return new Vector(this.getX()+ vec.getX(), this.getY()+vec.getY());
	}
	public Vector sub(Vector vec){
		return new Vector(this.getX()- vec.getX(), this.getY()-vec.getY());
	}
	public double multX(Vector vec){
		return vec.getX()* this.getX() + vec.getY() * this.getY();
	}
	public Vector multS(double value){
		return new Vector(value*this.getX(), value*this.getY());
	}
	public Vector getNormVec(){
		if(this.getY() == 0){ // berechnet einen normalen vektor zum Vector
			return new Vector(0,1);
		} else {
			return new Vector(1,-this.getX()/this.getY());
		}
	}
	public Vector getNormed(){
		double d = this.getLength();
		if(d == 0){
			return new Vector(0,0);
		}
		return new Vector(this.getX()/d, this.getY()/d);
	}
	public double getLength(){
		return Math.sqrt((this.getX()*this.getX())+(this.getY()*this.getY()));
	}
	public Vector setLength(double length){
		return this.getNormed().multS(length);
	}
	public double getAngele(Vector vec){
		if(this.getLength() == 0 || vec.getLength() == 0){
			return 0;
		}
		return Math.acos(this.multX(vec)/(this.getLength()*vec.getLength()));
	}
	public double getAngle(){
		return -Math.atan2(this.getY(), this.getX());
	}
}
